<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <script>
      let a = prompt('输入用户名')
      let b = prompt('输入密码')
      // let newArr = []
      let loginList = [
        { userName: 'admin', password: 'admin321' },
        { userName: 'zhangsan', password: 'zs321' },
        { userName: 'lisi', password: 'ls321' },
        { userName: 'yyqx', password: 'yyqx321' },
      ]

      // 现有的用户信息列表
      // 根据生成的token 去掉找到 对应的信息
      let userInfo = {
        token1: {
          city: '杭州',
          money: '1000w',
          sex: '女',
          userName: 'admin',
          password: 'admin321',
        },
        token2: {
          city: '北京',
          money: '1100w',
          sex: '女',
          userName: 'zhangsan',
          password: 'zs321',
        },
        token3: {
          city: '北京',
          money: '800w',
          sex: '男',
          userName: 'lisi',
          password: 'ls321',
        },
        token4: {
          city: '天津',
          money: '600w',
          sex: '男',
          userName: 'yyqx',
          password: 'yyqx321',
        },
      }

      function c(x, y) {
        for (let i = 0; i < x.length; i++) {
          // console.log( m[i].userName);
          // let xz = ath.floor(Math.random()*userInfo.length+1)
          if (a === x[i].userName && b === x[i].password) {
            alert(`登录成功,具体用户信息:
            city: '杭州',
          money: '1000w',
          sex: '女'`) 
            return alert('感谢参与')
            
          } else if (a !== x[i].userName && b !== x[i].password) {
            alert('登录失败')
          }
          let zc = +prompt(`1.注册
2.直接退出`)
          if (zc === 1) {
            let us = prompt('输入要注册的用户名')
            let ps = prompt('输入密码')
            loginList.push({ userName: us }, { password: ps })

            alert('注册成功，请登录')}
            else if (a === x[i].userName && b === x[i].password) {
               a = prompt('输入用户名')
               b = prompt('输入密码')
              alert(`登录成功,具体用户信息:
          city: '杭州',
          money: '1000w',
          sex: '女'`)
            }else {alert('登录失败')}
          

          if (zc === 2){
            alert('再见')
          }
            
        }
      }

      c(loginList, userInfo)
    </script>
  </body>
</html>
